PolyOsManager

open class PolyOsManager(    context: Context,     polyAppCallBacks: IPolyAppCallBacks?,     polyOsListener: PolyOsListener?) : IPolyOsManager

PolyOsManager exposes the api to communicate between a client application and PolyOs.

Usage:

    //Create an instance of PolyOsPlusManager
    polyOsManager = PolyOsManager(context);

    //Notify PolyOS when app state changes
    polyOsManager.notifyAppStateChanged(AppState(inCall = true))

    //Access services through the suspend function. Suspends until connected with polyos
    val isMuted = polyOsManager { audioService.isMicrophoneMuted }

    //Mute microphone
    polyOsManager { audioService.muteMicrophone(true)}


    //register listeners whenever polyos gets connected/reconnected
    polyOsManager.runWhenConnected {

        //Register for audio notifications
        audioService.registerAudioListener(audioListener)

        //Register for messages
        roomService.registerRoomListener(roomListener)
    }

Samples

import android.content.Context
import com.poly.polyos.AppState
import com.poly.polyos.PolyOsManager
import com.poly.polyos.audio.IPolyAudioListener
import com.poly.polyos.room.IPolyRoomListener
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
fun main() { 
   //sampleStart 
   /**
 * Sample usages for [PolyOsManager]
 */
class PolyOsSample {


    /**
     * Sample usage of [PolyOsManager]
     */
    suspend fun samplePolyOsManagerCreation(context: Context) {

        //Create PolyOsManager using context.
        val polyOsManager = PolyOsManager(context)

        //@see sampleNotifyOnAppStateChange of how to notify of app state changes
    }

    /**
     * Sample usage of how to listen for connection state changes
     */
    suspend fun samplePolyOsManagerConnectionStateListen(context: Context, scope: CoroutineScope) {

        //Create PolyOsManager using context.
        val polyOsManager = PolyOsManager(context)

        println("Connected ${polyOsManager.connectedState.value}")

        scope.launch {
            polyOsManager.connectedState.collect { connected ->
                println("Connected $connected")
            }
        }
    }

    /**
     * Notify polyos on app state changes like in call, content etc
     */
    suspend fun sampleNotifyOnAppStateChange(polyOsManager: PolyOsManager) {
        val currentAppState = AppState()

        //When in call, notify polyOs
        currentAppState.inCall = true
        polyOsManager.notifyAppStateChanged(currentAppState)

        //When out of  call, notify polyOs
        currentAppState.inCall = false
        polyOsManager.notifyAppStateChanged(currentAppState)
    }

    /**
     * Sample polyos api call using helper function that suspends until connected
     */
    suspend fun sampleAudioApi(polyOsManager: PolyOsManager) {
        //get mute state
        //call through suspend helper. suspends until connected with service
        val isMuted = polyOsManager { audioService.isMicrophoneMuted }

        //Mute audio
        polyOsManager { audioService.muteMicrophone(true) }
    }

    /**
     * Sample polyos api call using helper function that suspends until connected
     */
    fun sampleRunWhenConnected(polyOsManager: PolyOsManager, audioListener: IPolyAudioListener, roomListener: IPolyRoomListener) {

        //register listeners whenever polyos gets connected/reconnected
        polyOsManager.runWhenConnected {

            //Register for audio notifications
            audioService.registerAudioListener(audioListener)

            //Register for messages
            roomService.registerRoomListener(roomListener)
        }

        //Perform a one time task on first connection
        polyOsManager.runWhenConnected (oneshot = true) {
            val muted = audioService.isMicrophoneMuted
            println( "Audio is muted: $muted")
        }

    }
} 
   //sampleEnd
}

Parameters

context

Context to use

polyAppCallBacks

The IPolyAppCallBacks so that PolyOs can query/listen to app changes

polyOsListener

The PolyOsListener to know connected state and any other call backs

Constructors

Link copied to clipboard
fun PolyOsManager(context: Context)

Creates an instance of PolyOsManager.

Link copied to clipboard
fun PolyOsManager(    context: Context,     polyAppCallBacks: IPolyAppCallBacks?,     polyOsListener: PolyOsListener?)

Creates an instance of PolyOsManager.

Functions

Link copied to clipboard
open override fun destroy()

Called to destroy the manager instance

Link copied to clipboard
suspend operator fun <K> invoke(task: PolyOsManager.() -> K): K

Suspends until connected with polyos and then invokes the given task

Link copied to clipboard
suspend fun notifyAppStateChanged(appState: AppState)

Notifies polyos that the app state has changed.

Link copied to clipboard
fun runWhenConnected(    name: String? = null,     oneshot: Boolean = false,     task: PolyOsManager.() -> Unit)

Runs the given task if/when connected.

Link copied to clipboard
fun targetLocal(local: Boolean = true)

Sets whether to target the calls to primary or the local device.

Properties

Link copied to clipboard
open override val analyticsService: IPolyAnalyticsService

Returns IPolyAnalyticsService if connected.

Link copied to clipboard
open override val audioService: IPolyAudioService

Returns IPolyAudioService if connected.

Link copied to clipboard
open override val cameraService: IPolyCameraService

Returns IPolyCameraService if connected.

Link copied to clipboard
open override val connectedState: StateFlow<Boolean>

Emits the connected state changes

Link copied to clipboard
open override var isConnected: Boolean = false

Returns whether this is connected with the PolyOs

Link copied to clipboard
val isTargetLocal: Boolean = false

Returns whether this is currently targeting to local device.

Link copied to clipboard
open override val roomService: IPolyRoomService

Returns IPolyRoomService if connected.

Link copied to clipboard
open override val settingsService: IPolySettingsService

Returns IPolySettingsService if connected.

Link copied to clipboard
open override val systemService: IPolySystemService

Returns IPolySystemService if connected.

Link copied to clipboard
open override val version: String

Returns the version of PolyOs API